<?php
/* This file is part of Mirasol CMS
   (C) 2011 by Alban Technologies. Written by Chris Alban Hansen.
   Released under the terms of the GNU General Public License.
   See COPYING in the top level directory of the Mirasol CMS installation. */

include "{$_SERVER['DOCUMENT_ROOT']}/includes/config.php";
include "{$_SERVER['DOCUMENT_ROOT']}/includes/db.php";

$connection = db_open ();

$q = isset ($_GET['q']) || $_GET['q'] != "" ? mysql_real_escape_string ($_GET['q']) : "[root]";

/* Get xmlfeed */
$tbl_pages = db_maketablename ($table_pages);
$tbl_templates = db_maketablename ($table_templates);
$result = mysql_query ("SELECT xmlfeed, xslt FROM $tbl_pages LEFT JOIN $tbl_templates ON $tbl_templates.id=$tbl_pages.template WHERE path LIKE '$q' ORDER BY path");
if (mysql_num_rows ($result) > 0)
  {
    $row = mysql_fetch_array ($result);
    $xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".$row['xmlfeed'];
    $layout = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".$row['xslt'];
  }
mysql_free_result ($result);

db_close ($connection);

/* Prepare the XSL processor */
$doc = new DOMDocument ();
$xslproc = new XSLTProcessor ();

/* Load and import the layout */
$doc->loadXML ($layout);
$xslproc->importStyleSheet ($doc);

/* Load the xmlfeed */
$doc->loadXML ($xmldata);

/* Print the page */
print $xslproc->transformToXML ($doc);
?>
